package com.example.s01helloworld.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

// 过滤器配置方式1
// 添加@WebFilter注解
// 但需要在Application上添加如下注解:
// @ServletComponentScan(basePackages = {"com.example.s01helloworld.filter"})
// 因为SpringBoot默认不会扫描WebFilter

// 配置方式2
// 定义一个配置配置类
// 见WebConfigConfiguration

// 推荐使用方式2

//@WebFilter(urlPatterns = "/*")
public class MyFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        Filter.super.init(filterConfig);
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("doFilter 执行过滤");
        filterChain.doFilter(servletRequest,servletResponse);
    }

    @Override
    public void destroy() {
        Filter.super.destroy();
    }
}
